﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小说阅读 - 书羊网</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        .chapter-content {
            font-size: 18px;
            line-height: 1.8;
            letter-spacing: 0.05em;
        }
        .novel-info-card {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .chapter-list {
            max-height: 400px;
            overflow-y: auto;
        }
        .chapter-item {
            padding: 8px 15px;
            border-bottom: 1px solid #eee;
            cursor: pointer;
            transition: all 0.2s;
        }
        .chapter-item:hover {
            background-color: #f0f0f0;
        }
        .chapter-item.active {
            background-color: #e9ecef;
            font-weight: bold;
        }
        /* 限制内容宽度，避免图片过宽 */
        .container {
            max-width: 1200px;
        }
        /* 小说封面样式 */
        #novel-cover {
            max-width: 100%;
            height: auto;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        /* 目录样式 */
        .catalog-section {
            background-color: #fff;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
        }
        /* 章节内容区域样式 */
        .chapter-content-container {
            background-color: #fff;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
        }
        /* 章节列表容器样式 */
        #chapters-container {
            max-height: 500px;
            overflow-y: auto;
            border: 1px solid #eee;
            border-radius: 5px;
            padding: 10px;
        }
        .volume-title {
            font-weight: bold;
            background-color: #f0f0f0;
            padding: 8px 15px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<!-- 替换原有的导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">  <!-- 添加 fixed-top -->
    <div class="container">  <!-- 修改为 container 替代 container-fluid -->
        <a class="navbar-brand py-0" href="#">  <!-- 添加 py-0 减少纵向间距 -->
            <img src="https://mysteriouslamb.oss-cn-hangzhou.aliyuncs.com/icon.jpg" alt="" width="30" height="30">
            书羊网
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto">  <!-- 修改: me-3 变为 me-auto -->
                <li class="nav-item px-1">  <!-- 添加水平间距 -->
                    <a class="nav-link" href="${pageContext.request.contextPath}/MainPage/functionPage/index.jsp">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/MainPage/functionPage/library.jsp">书库</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="#">书架</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">角色扮演</a>
                </li>

                <c:if test="${not empty permission}">
                    <c:set var="hasAuthorPermission" value="false" />
                    <c:forEach var="perm" items="${permission}">
                        <c:if test="${perm == 2}"> <%-- 假设权限值为2代表作者 --%>
                            <c:set var="hasAuthorPermission" value="true" />
                        </c:if>
                    </c:forEach>

                    <c:choose>
                        <c:when test="${hasAuthorPermission}">
                            <li class="nav-item">
                                <a class="nav-link" href="${pageContext.request.contextPath}/MainPage/functionPage/authorWorkspace.jsp">作者工作台</a>
                            </li>
                        </c:when>
                        <c:otherwise>
                            <li class="nav-item">
                                <a class="nav-link" href="#">成为作者</a>
                            </li>
                        </c:otherwise>
                    </c:choose>

                    <%-- 管理下拉菜单 --%>
                    <%-- 移除了管理下拉菜单 --%>
                </c:if>
            </ul>
            <form class="d-flex mx-auto" id="searchForm" style="width: 40%; max-width: 400px;"> <!-- 修改: 添加 mx-auto 和 style -->
                <input class="form-control me-2 rounded-pill" type="search" placeholder="请输入书名或作者名" aria-label="Search" id="searchInput">
                <button class="btn btn-outline-success rounded-pill" type="submit" style="min-width: 60px;">搜索</button>
            </form>
            <div class="ms-auto d-flex align-items-center gap-3 me-3">
                <a class="d-flex align-items-center text-decoration-none" href="#" style="gap:12px">
                    <img src="${user.avatar_url}" alt="用户头像"
                         class="rounded-circle shadow-sm transition-all"
                         width="45" height="45"
                         style="transition:0.3s">
                    <div class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle fw-bold text-dark p-2 rounded-3"
                           href="#"
                           role="button"
                           data-bs-toggle="dropdown"
                           style="transition:0.3s">
                            ${user.username}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end border-0 shadow-sm">
                            <li><a class="dropdown-item py-2 text-danger rounded-2" href="${pageContext.request.contextPath}/API/user/logout">🚪 退出登录</a></li>
                        </ul>
                    </div>
                </a>
            </div>
        </div>
    </div>
</nav>

<!-- 主要内容区域 -->
<div class="container" style="margin-top: 80px; padding-top: 20px;">
    <!-- 小说基本信息区域 -->
    <div class="row mb-4">
        <!-- 小说封面 -->
        <div class="col-md-3">
            <img id="novel-cover" class="img-fluid rounded" src="" alt="小说封面">
        </div>
        <!-- 小说信息 -->
        <div class="col-md-9">
            <div class="novel-info-card">
                <h3 id="novel-title">加载中...</h3>
                <p><strong>作者：</strong><span id="novel-author">未知</span></p>
                <p><strong>简介：</strong><span id="novel-introduction">暂无简介</span></p>
                <p><strong>总章节数：</strong><span id="total-chapters">0</span></p>
                <!-- 若需要显示章节数量，可添加以下行 -->
                <p><strong>当前章节数：</strong><span id="chapter-count">0</span></p> 
                <p><strong>总字数：</strong><span id="novel-word-count">0</span></p>
                <button id="collectBtn" class="btn btn-outline-primary">加入书架</button>
            </div>
        </div>
    </div>
    
    <!-- 章节列表和内容区域 -->
    <div class="row">
        <!-- 分卷列表 -->
        <div class="col-md-4">
            <div class="catalog-section">
                <!-- 修改标题为分卷列表 -->
                <h4>分卷列表</h4> 
                <div id="volumes-container">
                    <!-- 分卷列表将由JS动态加载 -->
                    <div class="text-center py-3">加载中...</div>
                </div>
            </div>
        </div>
        
        <!-- 章节内容 -->
        <div class="col-md-8">
            <div class="chapter-content-container">
                <h4 id="volume-chapter-title">请选择分卷查看章节</h4>
                <div id="volume-chapters-content" class="chapter-content">
                    <div class="text-center py-5">请从左侧选择分卷查看该卷的所有章节</div>
                </div>
                <!-- 移除导航按钮 -->
                <!-- 
                <div class="d-flex justify-content-between mt-4" style="display: none;">
                    <button id="prevChapterBtn" class="btn btn-primary" disabled>上一章</button>
                    <button id="nextChapterBtn" class="btn btn-primary" disabled>下一章</button>
                </div>
                -->
            </div>
        </div>
    </div>
</div>

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
        crossorigin="anonymous"></script>
<!-- 引入小说阅读页面JS -->
<script src="${pageContext.request.contextPath}/MainPage/functionPage/page.js"></script>
</body>
</html>
